<%layout("/common/_layout.html"){%>
<%#ajax userTable:{%>
<div class="am-cf am-padding" style="padding:1rem 1.6rem 1.6rem 1rem;margin:0px;">
    <!--  padding:1px 2px 3px 4px;上、右、下,和左   -->
    <div class="am-fl am-cf"><strong class="am-text-primary am-text-lg">系统管理</strong> /
        <small>资源管理</small>
    </div>
</div>
<div class="am-g">
    <div class="am-u-sm-12">
        <form class="am-form" id="listForm" action="${base}/permission/list" method="post">
            <input type="hidden" id="keywords" name="keywords" value='${keywords!""}'/>
            <table class="am-table am-table-bordered am-table-radius table-main" style="padding:0;">
                <tbody>
                <tr>
                    <th class="am-text-middle">主键ID</th>
                    <td>
                        <div class="am-u-sm-10">
                            <input type="text" id="pmsID" class="am-form-field am-input-sm" value="${pmsID!}"
                                   maxlength="11" onkeyup="value=value.replace(/[^\d]/g,'') "
                                   onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace(/[^\d]/g,''))"/>
                        </div>
                    </td>
                    <th class="am-text-middle">资源名称</th>
                    <td>
                        <div class="am-u-sm-10">
                            <input type="text" id="pmsName" class="am-form-field am-input-sm" value="${pmsName!}"/>
                        </div>
                    </td>
                </tr>
                <tr>
                    <th class="am-text-middle">URL</th>
                    <td>
                        <div class="am-u-sm-10">
                            <input type="text" id="pmsUrl" class="am-form-field am-input-sm" value="${pmsUrl!}"/>
                        </div>
                    </td>
                    <th class="am-text-middle">父ID</th>
                    <td>
                        <div class="am-u-sm-10">
                            <input type="text" id="pmsParentID" class="am-form-field am-input-sm"
                                   value="${pmsParentID!}" maxlength="11" onkeyup="value=value.replace(/[^\d]/g,'') "
                                   onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace(/[^\d]/g,''))"/>
                        </div>
                    </td>
                </tr>
                <tr>
                    <th class="am-text-middle">LEVEL</th>
                    <td>
                        <div class="am-u-sm-10">
                            <select data-am-selected id="pmsLevel" name="pmsLevel">
                                <option value="0"
                                <%if(pmsLevel! == "0") {%>selected<%}%>>全部</option>
                                <option value="1"
                                <%if(pmsLevel! == "1") {%>selected<%}%>>1</option>
                                <option value="2"
                                <%if(pmsLevel! == "2") {%>selected<%}%>>2</option>
                                <option value="3"
                                <%if(pmsLevel! == "3") {%>selected<%}%>>3</option>
                                <option value="4"
                                <%if(pmsLevel! == "4") {%>selected<%}%>>4</option>
                                <option value="5"
                                <%if(pmsLevel! == "5") {%>selected<%}%>>5</option>
                            </select>
                        </div>
                    </td>
                    <th class="am-text-middle">节点类型</th>
                    <td>
                        <div class="am-u-sm-10">
                            <select data-am-selected id="pmsType" name="pmsType">
                                <option value="0"
                                <%if(pmsType! == "0") {%>selected<%}%>>全部</option>
                                <option value="1"
                                <%if(pmsType! == "1") {%>selected<%}%>>非叶子节点</option>
                                <option value="2"
                                <%if(pmsType! == "2") {%>selected<%}%>>叶子节点</option>
                            </select>
                        </div>
                    </td>
                </tr>
                <tr>
                    <th class="am-text-middle">是否有效</th>
                    <td>
                        <div class="am-u-sm-10">
                            <select data-am-selected id="is_deleted" name="is_deleted">
                                <option value="-1"
                                <%if(pmsDeleted! == "-1") {%>selected<%}%>>全部</option>
                                <option value="0"
                                <%if(pmsDeleted! == "0") {%>selected<%}%>>有效</option>
                                <option value="1"
                                <%if(pmsDeleted! == "1") {%>selected<%}%>>无效</option>
                            </select>
                        </div>
                    </td>
                    <td colspan="2"></td>
                </tr>
                <tr>


                    <td colspan="4">
                        <div align='right'>
                            <button type="button" class="am-btn am-btn-default am-btn-sm am-text-secondary"
                                    id="submit-btn">搜索
                            </button>
                        </div>
                    </td>
                </tr>
                </tbody>
            </table>
        </form>
    </div>
    <div class="am-u-sm-12 am-u-md-12" style="padding:0 1.6rem 1.6rem 1rem;margin:0;">
        <div class="am-btn-toolbar" style="padding-left:.5rem;">
            <div class="am-btn-group am-btn-group-xs">
                <%if(so.hasPermission("PERMISSION_ADD")) {%>
                <button type="button" class="am-btn am-btn-default" onclick="location.href='${base}/permission/add'">
                    <span class="am-icon-plus"></span> 新增
                </button>
                <%}%>
                <%if(so.hasPermission("PERMISSION_DELETE")) {%>
                <button type="button" id="deleteButton" disabled="disabled" class="am-btn am-btn-default"
                        onclick="deleteAll('${base}/permission/delete')"><span class="am-icon-trash-o"></span> 删除
                </button>
                <%}%>
            </div>
        </div>
    </div>
</div>
<div class="am-g">
    <div class="am-u-sm-12">
        <div class="am-scrollable-horizontal">
            <table class="am-table am-table-striped am-table-hover table-main">
                <thead>
                <tr class="am-text-nowrap">
                    <th class="table-check"><input type="checkbox" id="allCheck"></th>
                    <th class="table-id">主键ID</th>
                    <th class="table-title">资源名称</th>
                    <th class="table-title">是否有效</th>
                    <th class="table-title">URL</th>
                    <th class="table-title">CODE</th>
                    <th class="table-title">父ID</th>
                    <th class="table-title">LEVEL</th>
                    <th class="table-title">节点类型</th>
                    <th class="table-title">排序</th>
                    <th class="table-title">创建人</th>
                    <th class="table-date">创建时间</th>
                    <th class="table-title">最近更新人</th>
                    <th class="table-date">最近更新时间</th>
                    <th class="table-title">备注</th>
                    <th class="table-set">操作</th>
                </tr>
                </thead>
                <tbody>
                <%for(list in pager.list!){%>
                <tr>
                    <td><input type="checkbox" <%{%>name="ids" value="${list.id}"<%}%> /></td>
                    <td>${list.id}</td>
                    <td>${list.name}</td>
                    <td>
                        <%if(list.is_deleted == false){%>
                        是
                        <%}else{%>
                        否
                        <%}%>
                    </td>
                    <td>${list.url}</td>
                    <td>${list.permission}</td>
                    <td>${list.parent_id}</td>
                    <td>${list.level}</td>
                    <td>
                        <%if (list.type == 1){%>
                        非叶子节点
                        <%}else{%>
                        叶子节点
                        <%}%>
                    </td>
                    <td>${list.sort}</td>
                    <td>${list.creator}</td>
                    <td>${list.created_time, dateFormat="yyyy-MM-dd HH:mm:ss"}</td>
                    <td>${list.updator}</td>
                    <td>${list.last_updated_time, dateFormat="yyyy-MM-dd HH:mm:ss"}</td>
                    <td>${list.remark}</td>
                    <td>
                        <div class="am-btn-toolbar">
                            <div class="am-btn-group am-btn-group-xs">
                                <%if(so.hasPermission("PERMISSION_EDIT")) {%>
                                <button type="button" class="am-btn am-btn-default am-btn-xs am-text-secondary"
                                        onclick="location.href='${base}/permission/edit?id=${list.id}'"><span
                                        class="am-icon-pencil-square-o"></span>编辑
                                </button>
                                <%}%>
                            </div>
                        </div>
                    </td>
                </tr>
                <%}%>
                </tbody>
            </table>
        </div>
        <div class="am-cf">
            <!-- 分页 -->
            <%if (pager.list.~size > 0){%>
            <div class="am-fr">
                <% include("/admin/common_pager.tpl"){}%>
            </div>
            <%}else{%>
            <div class="am-kai">
                <h3>没有找到任何记录!</h3>
            </div>
            <%}%>
        </div>

    </div>
</div>

<script type="text/javascript">
    $(function () {
        var keywordsObj = {};
        $("#submit-btn").on("click", function () {
            if ($("#pmsName").val())
                keywordsObj.pmsName = $("#pmsName").val();
            if ($("#pmsID").val())
                keywordsObj.pmsID = $("#pmsID").val();
            if ($("#pmsUrl").val())
                keywordsObj.pmsUrl = $("#pmsUrl").val();
            if ($("#pmsParentID").val())
                keywordsObj.pmsParentID = $("#pmsParentID").val();
            if ($("#pmsLevel").val())
                keywordsObj.pmsLevel = $("#pmsLevel").val();
            if ($("#pmsType").val())
                keywordsObj.pmsType = $("#pmsType").val();
            if ($("#is_deleted").val())
                keywordsObj.pmsDeleted = $("#is_deleted").val();

            var keywords = "";
            if (!$.isEmptyObject(keywordsObj)) {
                keywords = JSON.stringify(keywordsObj);
            }
            console.log("keywords = " + keywords);

            $("#keywords").val(keywords);
            $("#listForm").submit();
        });
    });
</script>
<%}%>
<%}%>
